home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 June / PCWorld_2007-06_cd.bin / v cisle / tclock / tclocklight-040702-3.exe / source / exe / mouse2.c < prev    next >
C/C++ Source or Header  |  2004-04-04  |  3KB  |  116 lines

  1. /*-------------------------------------------------------------
  2.   mouse2.c : file drop, and etc.
  3.   (C) 1997-2003 Kazuto Sato
  4.   Please read readme.txt about the license.
  5.   
  6.   Written by Kazubon, Nanashi-san
  7. ---------------------------------------------------------------*/
  8.  
  9. #include "tclock.h"
  10.  
  11. /* Globals */
  12. void OnDropFiles(HWND hwnd, HDROP hdrop);
  13. void OnMouseWheel(HWND hwnd, WPARAM wParam, LPARAM lParam);
  14.  
  15. /* Statics */
  16. static char *m_section = "Mouse";
  17.  
  18. /*------------------------------------------------
  19.    when files dropped to the clock
  20. --------------------------------------------------*/
  21. void OnDropFiles(HWND hwnd, HDROP hdrop)
  22. {
  23.     char fname[MAX_PATH], app[MAX_PATH];
  24.     char *buf, *p;
  25.     int nType;
  26.     int i, num;
  27.     
  28.     nType = GetMyRegLong(m_section, "DropFiles", 0);
  29.     if(nType < 1 || 4 < nType)  return;
  30.     GetMyRegStr(m_section, "DropFilesApp", app, MAX_PATH, "");
  31.     if(nType == 2 || nType == 3 || nType == 4)
  32.     {
  33.         if(app[0] == 0) return;
  34.     }
  35.     
  36.     num = DragQueryFile(hdrop, (UINT)-1, NULL, 0);
  37.     if(num <= 0) return;
  38.     buf = malloc(num*(MAX_PATH+3));
  39.     if(buf == NULL) return;
  40.     
  41.     p = buf;
  42.     for(i = 0; i < num; i++)
  43.     {
  44.         DragQueryFile(hdrop, i, fname, MAX_PATH);
  45.         
  46.         // Recycle Bin, Copy to, Move to
  47.         if(nType == 1 || nType == 3 || nType == 4)
  48.         {
  49.             strcpy(p, fname); p += strlen(p) + 1;
  50.         }
  51.         // Open With...
  52.         else if(nType == 2)
  53.         {
  54.             strcpy(p, "\"");
  55.             strcat(p, fname);
  56.             strcat(p, "\"");
  57.             p += strlen(p);
  58.             if(num > 1 && i < num - 1) { *p = ' '; p++; }
  59.         }
  60.     }
  61.     *p = 0;
  62.     DragFinish(hdrop);
  63.     
  64.     // Recycle Bin, Copy to, Move to
  65.     if(nType == 1 || nType == 3 || nType == 4)
  66.     {
  67.         SHFILEOPSTRUCT shfos;
  68.         
  69.         memset(&shfos, 0, sizeof(SHFILEOPSTRUCT));
  70.         shfos.hwnd = NULL;
  71.         if(nType == 1) shfos.wFunc = FO_DELETE;
  72.         else if(nType == 3) shfos.wFunc = FO_COPY;
  73.         else if(nType == 4) shfos.wFunc = FO_MOVE;
  74.         shfos.pFrom = buf;
  75.         if(nType == 3 || nType == 4) shfos.pTo = app;
  76.         shfos.fFlags = FOF_ALLOWUNDO|FOF_NOCONFIRMATION;
  77.         SHFileOperation(&shfos);
  78.     }
  79.     // Open With...
  80.     else if(nType == 2)
  81.     {
  82.         char appabs[MAX_PATH], path[MAX_PATH];
  83.         SHELLEXECUTEINFO sei;
  84.         
  85.         RelToAbs(appabs, app);
  86.         
  87.         strcpy(path, appabs);
  88.         del_title(path);
  89.         
  90.         memset(&sei, 0, sizeof(sei));
  91.         sei.cbSize = sizeof(sei);
  92.         sei.lpFile = appabs;
  93.         sei.lpDirectory = path;
  94.         sei.lpParameters = buf;
  95.         sei.nShow = SW_SHOW;
  96.         ShellExecuteEx(&sei);
  97.     }
  98.     
  99.     free(buf);
  100. }
  101.  
  102. /*------------------------------------------------
  103.    when the mouse wheel is rotated
  104. --------------------------------------------------*/
  105. void OnMouseWheel(HWND hwnd, WPARAM wParam, LPARAM lParam)
  106. {
  107.     /*
  108.     int delta = (short)(wParam >> 16);
  109.     
  110.     char s[40];
  111.     wsprintf(s, "%d", delta);
  112.     WriteDebug(s);
  113.     */
  114. }
  115.  
  116.